import os
os.environ['HTTP_PROXY'] = 'http://192.168.32.19:10809'
os.environ['HTTPS_PROXY'] = 'http://192.168.32.19:10809'
import sys
from huggingface_hub import snapshot_download
repo_id = sys.argv[1]
local_dir = sys.argv[2]


if not len(sys.argv) == 3 or len(sys.argv) == 4 :
    print('使用方法，\n下载完整模型 : %s  repo_id local_dir '%sys.argv[0])
    print('下载模型的某个文件: %s  repo_id local_dir  filename '%sys.argv[0])
    exit()
token = ''
with open('config.yaml') as f:
    for line in f.readlines():
        sline = line.strip().split(':')
        key = sline[0]
        value = sline[1]
        if key == 'token':
            token = value

if len(sys.argv) == 3:

    snapshot_download(repo_id=repo_id,local_dir=local_dir,token=token) # https://huggingface.co/docs/hub/security-tokens
elif len(sys.argv) == 4:
    filename = sys.argv[3]
    from huggingface_hub import hf_hub_download
    hf_hub_download(repo_id=repo_id,filename=filename,local_dir=local_dir,token=token)
    

